﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace RIMS.Web.Utility.CacheUtility
{
    internal abstract class CacheUtility<T> where T : class
    {
        private static IList<T> _listAll;

        internal static IList<T> All
        {
            get { return _listAll; }
        }

        internal static int GetCount()
        {
            int listCount = 0;

            if (_listAll != null && _listAll.Count > 0)
            {
                listCount = _listAll.Count;
            }
            return listCount;
        }

        internal IList<T> AddToList
        {
            set
            {
                if(value != null)
                {
                    _listAll = value;
                }

            }
        }

        internal static void SetList(IList<T> list)
        {
            _listAll = list;
        }

        internal static bool Add(T item)
        {
            _listAll.Add(item);
            return true;
        }

        internal static bool Update(T item)
        {
            if (Delete(item))
            {
                return Add(item);
            }
            return false;
        }

        internal static bool Delete(T item)
        {
            return _listAll.Remove(item);
        }

        internal abstract T Read(Guid oid);
//        protected abstract Expression<Func<T, bool>> GetOIDSelector(Guid guid);
//
//        public T PickByOID(Guid guid)
//        {
//            return All .SingleOrDefault(predicate: GetOIDSelector(guid));
//        }
    }
}